﻿using System;
using System.Collections.Generic;

using DataFactory.Cms;
using IDAL.Cms;
using Model.Cms;
using Model.Base;
using Model.Config;
namespace BLL.Cms
{
    /// <summary>
    /// 业务层，内容管理，节点
    /// </summary>
    public class NodeBLL
    {
        /// <summary>
        /// 节点映射对象
        /// </summary>
        private INode dal = DataAccess.CreateNode();

        /// <summary>
        /// 新增节点
        /// </summary>
        /// <param name="nodeChannel">类别</param>
        /// <param name="nodeName">名称</param>
        /// <param name="seo">seo关键字</param>
        /// <param name="headScript">脚本</param>
        /// <param name="content">内容</param>
        /// <returns></returns>
        public int InsertNode(int nodeChannel, string nodeName, string seo, string headScript, string content) 
        {
            NodeInfo info = new NodeInfo();
            info.NodeChannel = new TermInfo();
            info.NodeChannel.TermID = nodeChannel;
            info.NodeName = nodeName;
            info.SeoKeyword = seo;
            info.HeadScript = headScript;
            info.BodyContent = content;
            return dal.InsertNodel(info);
        }

        /// <summary>
        /// 更新节点
        /// </summary>
        /// <param name="nodeID">编号</param>
        /// <param name="nodeChannel">类别</param>
        /// <param name="nodeName">名称</param>
        /// <param name="seo">seo关键字</param>
        /// <param name="headScript">脚本</param>
        /// <param name="content">内容</param>
        /// <returns></returns>
        public bool UpdateNode(int nodeID, int nodeChannel, string nodeName, string seo, string headScript, string content) 
        {
            NodeInfo info = new NodeInfo();
            info.NodeID = nodeID;
            info.NodeChannel = new TermInfo();
            info.NodeChannel.TermID = nodeChannel;
            info.NodeName = nodeName;
            info.SeoKeyword = seo;
            info.HeadScript = headScript;
            info.BodyContent = content;
            return dal.UpdateNode(info);
        }

        /// <summary>
        /// 删除节点
        /// </summary>
        /// <param name="nodeID"></param>
        /// <returns></returns>
        public bool DeleteNode(int nodeID) 
        {
            return dal.DeleteNodel(nodeID, "", 0);
        }

        /// <summary>
        /// 根据编号获取节点
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public NodeInfo GetNodeByID(int id) 
        {
            return dal.GetNodeByID(id);
        }

        /// <summary>
        /// 后台节点列表
        /// </summary>
        /// <param name="nodeChannel"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public IList<NodeInfo> BackList(int nodeChannel, int pageIndex, int pageSize, out int recordCount) 
        {
            NodeCondition condition = new NodeCondition();
            condition.NodeChannelID = nodeChannel;
            condition.PageIndex = pageIndex;
            condition.PageSize = pageSize;
            condition.OrderBy = "AddTime DESC";
            return dal.ListNode(condition, out recordCount);
        }
    }
}
